<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>GMemoryOutputStream</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
<link rel="start" href="index.html" title="GIO Reference Manual">
<link rel="up" href="streaming.html" title="Streaming I/O">
<link rel="prev" href="GMemoryInputStream.html" title="GMemoryInputStream">
<link rel="next" href="GBufferedInputStream.html" title="GBufferedInputStream">
<meta name="generator" content="GTK-Doc V1.9 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="part" href="pt01.html" title="Part&#160;I.&#160;GIO Overview">
<link rel="chapter" href="ch01.html" title="Introduction">
<link rel="chapter" href="ch02.html" title="Compiling GIO applications">
<link rel="chapter" href="ch03.html" title="Running GIO applications">
<link rel="chapter" href="gio-extension-points.html" title="Extending GIO">
<link rel="part" href="pt02.html" title="Part&#160;II.&#160;API Reference">
<link rel="chapter" href="file_ops.html" title="File Operations">
<link rel="chapter" href="file_mon.html" title="File System Monitoring">
<link rel="chapter" href="async.html" title="Asynchronous I/O">
<link rel="chapter" href="streaming.html" title="Streaming I/O">
<link rel="chapter" href="types.html" title="File types and applications">
<link rel="chapter" href="volume_mon.html" title="Volumes and Drives">
<link rel="chapter" href="icons.html" title="Icons">
<link rel="chapter" href="utils.html" title="Utilities">
<link rel="chapter" href="extending.html" title="Extending GIO">
<link rel="part" href="migrating.html" title="Part&#160;III.&#160;Migrating to GIO">
<link rel="chapter" href="ch14.html" title="Migrating from POSIX to GIO">
<link rel="chapter" href="ch15.html" title="Migrating from GnomeVFS to GIO">
<link rel="chapter" href="gio-hierarchy.html" title="Object Hierarchy">
<link rel="index" href="ix01.html" title="Index">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="GMemoryInputStream.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="streaming.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GIO Reference Manual</th>
<td><a accesskey="n" href="GBufferedInputStream.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2785860" class="shortcut">Top</a>
                  &#160;|&#160;
                  <a href="#id2847716" class="shortcut">Description</a>
                  &#160;|&#160;
                  <a href="#id2847665" class="shortcut">Object Hierarchy</a>
                  &#160;|&#160;
                  <a href="#id2847695" class="shortcut">Implemented Interfaces</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="GMemoryOutputStream"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id2785860"></a><span class="refentrytitle">GMemoryOutputStream</span>
</h2>
<p>GMemoryOutputStream &#8212; Streaming output operations on memory chunks</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">

#include &lt;gio/gio.h&gt;


<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a>            (<a class="link" href="GMemoryOutputStream.html#GReallocFunc">*GReallocFunc</a>)                     (<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a> size);
                    <a class="link" href="GMemoryOutputStream.html#GMemoryOutputStream-struct">GMemoryOutputStream</a>;
<a class="link" href="GOutputStream.html" title="GOutputStream">GOutputStream</a>*      <a class="link" href="GMemoryOutputStream.html#g-memory-output-stream-new">g_memory_output_stream_new</a>          (<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a> len,
                                                         <a class="link" href="GMemoryOutputStream.html#GReallocFunc">GReallocFunc</a> realloc_fn,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Datasets.html#GDestroyNotify"
>GDestroyNotify</a> destroy);
<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a>            <a class="link" href="GMemoryOutputStream.html#g-memory-output-stream-get-data">g_memory_output_stream_get_data</a>     (<a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream">GMemoryOutputStream</a> *ostream);
<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a>               <a class="link" href="GMemoryOutputStream.html#g-memory-output-stream-get-size">g_memory_output_stream_get_size</a>     (<a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream">GMemoryOutputStream</a> *ostream);


</pre>
</div>
<div class="refsect1" lang="en">
<a name="id2847665"></a><h2>Object Hierarchy</h2>
<pre class="synopsis">

  <a
href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject"
>GObject</a>
   +----<a class="link" href="GOutputStream.html" title="GOutputStream">GOutputStream</a>
         +----GMemoryOutputStream
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id2847695"></a><h2>Implemented Interfaces</h2>
<p>
GMemoryOutputStream implements
 <a class="link" href="GSeekable.html" title="GSeekable">GSeekable</a>.</p>
</div>
<div class="refsect1" lang="en">
<a name="id2847716"></a><h2>Description</h2>
<p>
<a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream"><span class="type">GMemoryOutputStream</span></a> is a class for using arbitrary
memory chunks as output for GIO streaming output operations.</p>
<p>

</p>
</div>
<div class="refsect1" lang="en">
<a name="id2847745"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id2847755"></a><h3>
<a name="GReallocFunc"></a>GReallocFunc ()</h3>
<a class="indexterm" name="id2856042"></a><pre class="programlisting"><a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a>            (*GReallocFunc)                     (<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a> size);</pre>
<p>
Changes the size of the memory block pointed to by <em class="parameter"><code>data</code></em> to
<em class="parameter"><code>size</code></em> bytes. 
</p>
<p>
The function should have the same semantics as <code class="function">realloc()</code>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></p></td>
<td> memory block to reallocate
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>size</code></em>&#160;:</span></p></td>
<td> size to reallocate <em class="parameter"><code>data</code></em> to
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> a pointer to the reallocated memory
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2856155"></a><h3>
<a name="GMemoryOutputStream-struct"></a>GMemoryOutputStream</h3>
<a class="indexterm" name="id2856167"></a><pre class="programlisting">typedef struct _GMemoryOutputStream GMemoryOutputStream;</pre>
<p>
Implements <a class="link" href="GOutputStream.html" title="GOutputStream"><span class="type">GOutputStream</span></a> for arbitrary memory chunks.</p>
<p>

</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2856194"></a><h3>
<a name="g-memory-output-stream-new"></a>g_memory_output_stream_new ()</h3>
<a class="indexterm" name="id2856238"></a><pre class="programlisting"><a class="link" href="GOutputStream.html" title="GOutputStream">GOutputStream</a>*      g_memory_output_stream_new          (<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a> data,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a> len,
                                                         <a class="link" href="GMemoryOutputStream.html#GReallocFunc">GReallocFunc</a> realloc_fn,
                                                         <a
href="/usr/share/gtk-doc/html/glib/glib-Datasets.html#GDestroyNotify"
>GDestroyNotify</a> destroy);</pre>
<p>
Creates a new <a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream"><span class="type">GMemoryOutputStream</span></a>. 
</p>
<p>
If <em class="parameter"><code>data</code></em> is non-<a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a>, the stream  will use that for its internal storage.
If <em class="parameter"><code>realloc_fn</code></em> is non-<a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a>, it will be used for resizing the internal
storage when necessary. To construct a fixed-size output stream, 
pass <a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a> as <em class="parameter"><code>realloc_fn</code></em>.
</p>
<div class="informalexample"><pre class="programlisting">
/* a stream that can grow */
stream = g_memory_output_stream_new (NULL, 0, realloc, free);

/* a fixed-size stream */
data = malloc (200);
stream2 = g_memory_output_stream_new (data, 200, NULL, free);
</pre></div>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></p></td>
<td> pointer to a chunk of memory to use, or <a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>len</code></em>&#160;:</span></p></td>
<td> the size of <em class="parameter"><code>data</code></em>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>realloc_fn</code></em>&#160;:</span></p></td>
<td> a function with <code class="function">realloc()</code> semantics to be called when 
    <em class="parameter"><code>data</code></em> needs to be grown, or <a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>destroy</code></em>&#160;:</span></p></td>
<td> a function to be called on <em class="parameter"><code>data</code></em> when the stream is finalized,
    or <a
href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS"
><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> A newly created <a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream"><span class="type">GMemoryOutputStream</span></a> object.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2856493"></a><h3>
<a name="g-memory-output-stream-get-data"></a>g_memory_output_stream_get_data ()</h3>
<a class="indexterm" name="id2858536"></a><pre class="programlisting"><a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer"
>gpointer</a>            g_memory_output_stream_get_data     (<a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream">GMemoryOutputStream</a> *ostream);</pre>
<p>
Gets any loaded data from the <em class="parameter"><code>ostream</code></em>. 
</p>
<p>
Note that the returned pointer may become invalid on the next 
write or truncate operation on the stream.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>ostream</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream"><span class="type">GMemoryOutputStream</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> pointer to the stream's data
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2858615"></a><h3>
<a name="g-memory-output-stream-get-size"></a>g_memory_output_stream_get_size ()</h3>
<a class="indexterm" name="id2858628"></a><pre class="programlisting"><a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gsize"
>gsize</a>               g_memory_output_stream_get_size     (<a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream">GMemoryOutputStream</a> *ostream);</pre>
<p>
Gets the size of the currently allocated data area (availible from
<a class="link" href="GMemoryOutputStream.html#g-memory-output-stream-get-data"><code class="function">g_memory_output_stream_get_data()</code></a>). If the stream isn't
growable (no realloc was passed to <a class="link" href="GMemoryOutputStream.html#g-memory-output-stream-new"><code class="function">g_memory_output_stream_new()</code></a>) then
this is the max size of the stream and further writes
will return G_IO_ERROR_NO_SPACE.
</p>
<p>
Note that for growable streams the returned size may become invalid on
the next write or truncate operation on the stream.
</p>
<p>
Note, this does not return the number of bytes written to the stream.
In glib 2.18 this is availible with <code class="function">g_memory_output_stream_get_data_size()</code>,
but for 2.16 you have to use <a class="link" href="GSeekable.html#g-seekable-seek"><code class="function">g_seekable_seek()</code></a> to G_SEEK_END
and call <a class="link" href="GSeekable.html#g-seekable-tell"><code class="function">g_seekable_tell()</code></a> to achive this.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>ostream</code></em>&#160;:</span></p></td>
<td> a <a class="link" href="GMemoryOutputStream.html" title="GMemoryOutputStream"><span class="type">GMemoryOutputStream</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td> the number of bytes allocated for the data buffer
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1" lang="en">
<a name="id2858761"></a><h2>See Also</h2>
<a class="link" href="GMemoryInputStream.html" title="GMemoryInputStream"><span class="type">GMemoryInputStream</span></a>
</div>
<div class="refsect1" lang="en">
<a name="id2858775"></a><div class="refsect2" lang="en"><a name="id2858776"></a></div>
<hr>
<div class="refsect2" lang="en"><a name="id2858778"></a></div>
</div>
</div>
</body>
</html>
